package com.usfuture.chart.techanly
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.KeyboardEvent;
	import flash.geom.Point;
	import flash.ui.Keyboard;

	public class AbstractTechProperty extends EventDispatcher
	{
		public static const CHANGE="pro_change";
		
		public static const LINE_ONE_MINUTE:String='one';
		public static const LINE_FIVE_MINUTE:String='five';
		public static const LINE_TEN_MINUTE:String='ten';
		public static const LINE_FIFTEEN_MINUTE:String='fifteen';
		public static const LINE_TWENTY_MINUTE:String='twenty';
		public static const LINE_THIRTY_MINUTE:String='thirty';
		public static const LINE_SIXTY_MINUTE:String='sixty';
		public static const LINE_DAILY:String='day';
		public static const LINE_WEEK:String='week';
		public static const LINE_MONTH:String='month';
		
		
		public static var leftWidthX:Number=60;//K线图距画布左边的距离
		public static var rightWidthX:Number=60;//K线图距画布左边的距离
		public static var canvasWidth:Number;//绘制K线的面板宽度
		public static var lineType:String=LINE_DAILY;//K线图距画布左边的距离
		
		private  var _data:Array;
		private  var _startPos:int;//要画K线的数据开始位置
		private  var _mode:Boolean=true;//true：按K线宽度画，false：按K线数量画
		private  var _lineNum:uint=90;//要画的K线数量
		private  var _lineWidth:Number=20;//K线宽度
		private  var _lineMergin:Number=4;//K线间隙
		private  var _relativePos:uint;//当前屏幕上鼠标所在的K线位置
		private  var _absolutePos:uint;//当前数据源上鼠标所在的K线位置
		
		protected function init():void{
			
		}
		
		public static function lineTypeShow(lineType:String):String{
			switch(lineType){
				case LINE_ONE_MINUTE: return '1分鐘';
				case LINE_FIVE_MINUTE: return '5分鐘';
				case LINE_TEN_MINUTE: return '10分鐘';
				case LINE_FIFTEEN_MINUTE: return '15分鐘';
				case LINE_TWENTY_MINUTE: return '20分鐘';
				case LINE_THIRTY_MINUTE: return '30分鐘';
				case LINE_SIXTY_MINUTE: return '60分鐘';
				case LINE_DAILY: return '日線';
				case LINE_WEEK: return '周線';
				case LINE_MONTH: return '月線';
				default:return '';
			}
		}
		
		/**
		 * 根据键盘输入更改K线的属性并重绘
		 **/
		public final function keyboardEvent(event:KeyboardEvent):void
		{
			switch (KeyboardEvent(event).keyCode)
			{
				case Keyboard.UP:
					keyUpHandler();
					break;
				case Keyboard.DOWN:
					keyDownHandler();
					break;
				case Keyboard.LEFT:
					keyLeftHandler();
					break;
				case Keyboard.RIGHT:
					keyRightHandler();
					break;
			}
			dispatchEvent(new Event(CHANGE))
		}
		
		protected function keyUpHandler():void{
			
		}
		
		protected function keyDownHandler():void{
			
		}
		
		protected function keyLeftHandler():void{
			
		}
		
		protected function keyRightHandler():void{
			
		}


		public  function get data():Array
		{
			return _data;
		}

		public  function set data(value:Array):void
		{
			_data = value;
			init();
			startPos=data.length;
			if (lineNum >= data.length)
				lineNum = data.length;
		}
		
		public function get lineNum():uint{
			return _lineNum;
			
		}
		
		public function set lineNum(value:uint):void{
			_lineNum = value;
			if(startPos==data.length&&_lineNum>data.length)
				_lineNum = data.length;
		}

		public  function get relativePos():uint
		{
			return _relativePos;
		}

		public  function set relativePos(value:uint):void
		{
			_relativePos = value;
			if(relativePos<0) relativePos=0;
			if(relativePos>=lineNum) relativePos = lineNum - 1;
			
			_absolutePos = startPos-lineNum+relativePos>=data.length?data.length-1:startPos-lineNum+relativePos;
			
		}

		public  function get absolutePos():uint
		{
			return _absolutePos;
		}

		public function get startPos():int
		{
			return _startPos;
		}

		public function set startPos(value:int):void
		{
			_startPos = value;
			dispatchEvent(new Event(CHANGE))
		}

		public function get mode():Boolean
		{
			return _mode;
		}

		public function set mode(value:Boolean):void
		{
			_mode = value;
		}

		public function get lineWidth():Number
		{
			return _lineWidth;
		}

		public function set lineWidth(value:Number):void
		{
			_lineWidth = value;
		}

		public function get lineMergin():Number
		{
			return _lineMergin;
		}

		public function set lineMergin(value:Number):void
		{
			_lineMergin = value;
		}
		

	}
}